/*
 * TaskWrapper.java
 *
 * Created on April 22, 2007, 9:09 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.xeerkat.agent;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 *
 * @author alex
 */
public abstract class SingleOperation implements Task
{
   
   protected UUID id;
   protected AtomicBoolean running;
   
   /** Creates a new instance of TaskWrapper */
   public SingleOperation(AtomicBoolean control)
   {
      id = UUID.randomUUID();
      running = control;
   }
   
   public UUID getId() {
      return id;
   }
   
   public void cancel() {
      running.set(false);
   }
   
   public abstract void execute();
   
   public boolean isComplete() {
      return !running.get();
   }
   
   public void run() {
      if (running.get()) {
         execute();
         running.set(false);
      }
   }
}
